package com.breakfast.fun.ui.user.recharge.rechargerecord;

import com.breakfast.fun.Constant;
import com.breakfast.fun.data.entity.user.recharge.RechargeRecord;
import com.breakfast.fun.util.Api;
import com.breakfast.fun.util.T;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by yukai on 16/9/11.
 */
public class RechargeRecordPresenter extends RechargeRecordContract.Presenter {
    @Override
    public void getRecord() {
        Map<String, String> map = Api.getInstance().getBaseParams();

        map.put("action", "list");
        map.put("accountId", Constant.getUserData().getId() + "");

        showLoadingDialog(true);
        rxManager.add(model.getRechargeRecordModel(map)
                .subscribeOn(Schedulers.computation())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new Subscriber<RechargeRecord>() {
                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        T.show("获取数据失败");
                        hideLoadingDialog();
                        e.printStackTrace();
                    }

                    @Override
                    public void onNext(RechargeRecord record) {
                        if (record.isSuccess()) {
                            view.showRecord(record);
                        } else {
                            T.show(record.getMsg());
                        }
                        hideLoadingDialog();
                    }


                }));
    }

    @Override
    public void onStart() {
        getRecord();
    }
}
